/*
 * Copyright 2020-2025 the original author or authors.
 * You cannot use this file unless authorized by the author.
 */

package org.ipig.commons.collections;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <ul>
 * 基于LRU（The Least Recently Used，最近最久未使用算法）算法的ConcurrentHashMap 并发版。
 * <li>LRU算法的思想是：如果一个数据在最近一段时间没有被访问到，那么可以认为在将来它被访问的可能性也很小。因此，当空间满时，最久没有访问的数据最先被置换（淘汰）</>
 *</ul>
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id: LeastRecentlyUsedConcurrentCache.java 3 2020-01-21 09:36:33Z ts <comchnts@163.com> $$
 * @since 1.0
 */
public class LeastRecentlyUsedConcurrentCache<K, V> extends ConcurrentHashMap<K, V> {
    private final int maxCapacity;
    private final float loadFactor;

    public LeastRecentlyUsedConcurrentCache(int maxCapacity,float loadFactor) {
        super(maxCapacity, loadFactor);
        this.maxCapacity = maxCapacity;
        this.loadFactor = loadFactor;
    }

    public Collection<Map.Entry<K, V>> getAll() {
        return new ArrayList<Map.Entry<K, V>>(super.entrySet());
    }
}
